package com.fr.base.core;

import com.fr.base.DefaultValues;
import com.fr.base.FRContext;
import com.fr.base.FRFont;
import com.fr.base.Style;
import com.fr.base.background.Background;
import java.awt.Color;
import java.text.DecimalFormat;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;

public class StyleUtils
{
  public static Style applyCellStyle(Style paramStyle1, Style paramStyle2, Style paramStyle3)
  {
    if (paramStyle3 == null)
      return paramStyle3;
    if (paramStyle1 == null)
      paramStyle1 = Style.DEFAULT_STYLE;
    if (paramStyle2 == null)
      paramStyle2 = Style.DEFAULT_STYLE;
    if (!(ComparatorUtils.equals(paramStyle2.getFormat(), paramStyle1.getFormat())))
      if (paramStyle2.getFormat() == null)
        paramStyle3 = paramStyle3.deriveFormat(null);
      else
        paramStyle3 = paramStyle3.deriveFormat((Format)paramStyle2.getFormat().clone());
    if (!(ComparatorUtils.equals(paramStyle2.getFRFont(), paramStyle1.getFRFont())))
    {
      FRFont localFRFont1 = paramStyle2.getFRFont();
      FRFont localFRFont2 = paramStyle1.getFRFont();
      if (localFRFont1 == null)
      {
        paramStyle3 = paramStyle3.deriveFRFont(null);
      }
      else if (localFRFont2 == null)
      {
        paramStyle3 = paramStyle3.deriveFRFont(localFRFont1);
      }
      else
      {
        if (!(ComparatorUtils.equals(localFRFont1.getFontName(), localFRFont2.getFontName())))
          paramStyle3 = setReportFontName(paramStyle3, localFRFont1.getFontName());
        if (localFRFont1.getStyle() != localFRFont2.getStyle())
          paramStyle3 = setReportFontStyle(paramStyle3, localFRFont1.getStyle());
        if (localFRFont1.getSize() != localFRFont2.getSize())
          paramStyle3 = setReportFontSize(paramStyle3, localFRFont1.getSize());
        if (!(ComparatorUtils.equals(localFRFont1.getForeground(), localFRFont2.getForeground())))
          paramStyle3 = setReportFontForeground(paramStyle3, localFRFont1.getForeground());
        if (localFRFont1.getUnderline() != localFRFont2.getUnderline())
          paramStyle3 = setReportFontUnderline2(paramStyle3, localFRFont1.getUnderline());
        if (localFRFont1.isStrikethrough() != localFRFont2.isStrikethrough())
          paramStyle3 = setReportFontStrikethrough(paramStyle3, localFRFont1.isStrikethrough());
        if (localFRFont1.isShadow() != localFRFont2.isShadow())
          paramStyle3 = setReportFontShadow(paramStyle3, localFRFont1.isShadow());
        if (localFRFont1.isSuperscript() != localFRFont2.isSuperscript())
          paramStyle3 = setReportSuperscript(paramStyle3, localFRFont1.isSuperscript());
        if (localFRFont1.isSubscript() != localFRFont2.isSubscript())
          paramStyle3 = setReportSubscript(paramStyle3, localFRFont1.isSubscript());
      }
    }
    if (!(ComparatorUtils.equals(paramStyle2.getBackground(), paramStyle1.getBackground())))
      if (paramStyle2.getBackground() == null)
        paramStyle3 = paramStyle3.deriveBackground(null);
      else
        try
        {
          paramStyle3 = paramStyle3.deriveBackground((Background)paramStyle2.getBackground().clone());
        }
        catch (CloneNotSupportedException localCloneNotSupportedException)
        {
          FRContext.getLogger().log(Level.WARNING, localCloneNotSupportedException.getMessage(), localCloneNotSupportedException);
        }
    int i = paramStyle3.getBorderTop();
    int j = paramStyle3.getBorderBottom();
    int k = paramStyle3.getBorderLeft();
    int l = paramStyle3.getBorderRight();
    Color localColor1 = paramStyle3.getBorderTopColor();
    Color localColor2 = paramStyle3.getBorderBottomColor();
    Color localColor3 = paramStyle3.getBorderLeftColor();
    Color localColor4 = paramStyle3.getBorderRightColor();
    int i1 = 0;
    if (paramStyle2.getBorderTop() != paramStyle1.getBorderTop())
    {
      i = paramStyle2.getBorderTop();
      i1 = 1;
    }
    if (paramStyle2.getBorderLeft() != paramStyle1.getBorderLeft())
    {
      k = paramStyle2.getBorderLeft();
      i1 = 1;
    }
    if (paramStyle2.getBorderBottom() != paramStyle1.getBorderBottom())
    {
      j = paramStyle2.getBorderBottom();
      i1 = 1;
    }
    if (paramStyle2.getBorderRight() != paramStyle1.getBorderRight())
    {
      l = paramStyle2.getBorderRight();
      i1 = 1;
    }
    if (!(ComparatorUtils.equals(paramStyle2.getBorderTopColor(), paramStyle1.getBorderTopColor())))
    {
      localColor1 = paramStyle2.getBorderTopColor();
      i1 = 1;
    }
    if (!(ComparatorUtils.equals(paramStyle2.getBorderLeftColor(), paramStyle1.getBorderLeftColor())))
    {
      localColor3 = paramStyle2.getBorderLeftColor();
      i1 = 1;
    }
    if (!(ComparatorUtils.equals(paramStyle2.getBorderBottomColor(), paramStyle1.getBorderBottomColor())))
    {
      localColor2 = paramStyle2.getBorderBottomColor();
      i1 = 1;
    }
    if (!(ComparatorUtils.equals(paramStyle2.getBorderRightColor(), paramStyle1.getBorderRightColor())))
    {
      localColor4 = paramStyle2.getBorderRightColor();
      i1 = 1;
    }
    if (i1 != 0)
      paramStyle3 = paramStyle3.deriveBorder(i, localColor1, j, localColor2, k, localColor3, l, localColor4);
    if (paramStyle2.getHorizontalAlignment() != paramStyle1.getHorizontalAlignment())
      paramStyle3 = paramStyle3.deriveHorizontalAlignment(paramStyle2.getHorizontalAlignment());
    if (paramStyle2.getVerticalAlignment() != paramStyle1.getVerticalAlignment())
      paramStyle3 = paramStyle3.deriveVerticalAlignment(paramStyle2.getVerticalAlignment());
    if (paramStyle2.getTextStyle() != paramStyle1.getTextStyle())
      paramStyle3 = paramStyle3.deriveTextStyle(paramStyle2.getTextStyle());
    if (paramStyle2.getImageLayout() != paramStyle1.getImageLayout())
      paramStyle3 = paramStyle3.deriveImageLayout(paramStyle2.getImageLayout());
    if (paramStyle2.getVerticalText() != paramStyle1.getVerticalText())
      paramStyle3 = paramStyle3.deriveVerticalText(paramStyle2.getVerticalText());
    if (paramStyle2.getTextDirection() != paramStyle1.getTextDirection())
      paramStyle3 = paramStyle3.deriveTextDirection(paramStyle2.getTextDirection());
    if (paramStyle2.getRotation() != paramStyle1.getRotation())
      paramStyle3 = paramStyle3.deriveRotation(paramStyle2.getRotation());
    if (paramStyle2.getPaddingLeft() != paramStyle1.getPaddingLeft())
      paramStyle3 = paramStyle3.derivePaddingLeft(paramStyle2.getPaddingLeft());
    if (paramStyle2.getPaddingRight() != paramStyle1.getPaddingRight())
      paramStyle3 = paramStyle3.derivePaddingRight(paramStyle2.getPaddingRight());
    if (paramStyle2.getSpacingBefore() != paramStyle1.getSpacingBefore())
      paramStyle3 = paramStyle3.deriveSpacingBefore(paramStyle2.getSpacingBefore());
    if (paramStyle2.getSpacingAfter() != paramStyle1.getSpacingAfter())
      paramStyle3 = paramStyle3.deriveSpacingAfter(paramStyle2.getSpacingAfter());
    if (paramStyle2.getLineSpacing() != paramStyle1.getLineSpacing())
      paramStyle3 = paramStyle3.deriveLineSpacing(paramStyle2.getLineSpacing());
    return paramStyle3;
  }

  public static Style setReportFontName(Style paramStyle, String paramString)
  {
    FRFont localFRFont = paramStyle.getFRFont();
    if (localFRFont == null)
    {
      localObject = FRContext.getDefaultValues();
      localFRFont = ((DefaultValues)localObject).getFRFont();
    }
    Object localObject = localFRFont.applyName(paramString);
    return ((Style)paramStyle.deriveFRFont((FRFont)localObject));
  }

  public static Style setReportFontStyle(Style paramStyle, int paramInt)
  {
    FRFont localFRFont = paramStyle.getFRFont();
    if (localFRFont == null)
    {
      localObject = FRContext.getDefaultValues();
      localFRFont = ((DefaultValues)localObject).getFRFont();
    }
    Object localObject = localFRFont.applyStyle(paramInt);
    return ((Style)paramStyle.deriveFRFont((FRFont)localObject));
  }

  public static Style boldReportFont(Style paramStyle)
  {
    return innerBoldCellFont(paramStyle, true);
  }

  public static Style unBoldReportFont(Style paramStyle)
  {
    return innerBoldCellFont(paramStyle, false);
  }

  private static Style innerBoldCellFont(Style paramStyle, boolean paramBoolean)
  {
    int i;
    FRFont localFRFont1 = paramStyle.getFRFont();
    if (localFRFont1 == null)
    {
      DefaultValues localDefaultValues = FRContext.getDefaultValues();
      localFRFont1 = localDefaultValues.getFRFont();
    }
    if (paramBoolean)
      if (localFRFont1.isItalic())
        i = 3;
      else
        i = 1;
    else if (localFRFont1.isItalic())
      i = 2;
    else
      i = 0;
    FRFont localFRFont2 = localFRFont1.applyStyle(i);
    return paramStyle.deriveFRFont(localFRFont2);
  }

  public static Style italicReportFont(Style paramStyle)
  {
    return innerItalicCellFont(paramStyle, true);
  }

  public static Style unItalicReportFont(Style paramStyle)
  {
    return innerItalicCellFont(paramStyle, false);
  }

  private static Style innerItalicCellFont(Style paramStyle, boolean paramBoolean)
  {
    int i;
    FRFont localFRFont1 = paramStyle.getFRFont();
    if (localFRFont1 == null)
    {
      DefaultValues localDefaultValues = FRContext.getDefaultValues();
      localFRFont1 = localDefaultValues.getFRFont();
    }
    if (paramBoolean)
      if (localFRFont1.isBold())
        i = 3;
      else
        i = 2;
    else if (localFRFont1.isBold())
      i = 1;
    else
      i = 0;
    FRFont localFRFont2 = localFRFont1.applyStyle(i);
    return paramStyle.deriveFRFont(localFRFont2);
  }

  public static Style setReportFontStrikethrough(Style paramStyle, boolean paramBoolean)
  {
    FRFont localFRFont = paramStyle.getFRFont();
    if (localFRFont == null)
    {
      DefaultValues localDefaultValues = FRContext.getDefaultValues();
      localFRFont = localDefaultValues.getFRFont();
    }
    else
    {
      localFRFont = localFRFont.applyStrikethrough(paramBoolean);
    }
    return paramStyle.deriveFRFont(localFRFont);
  }

  public static Style setReportFontShadow(Style paramStyle, boolean paramBoolean)
  {
    FRFont localFRFont = paramStyle.getFRFont();
    if (localFRFont == null)
    {
      DefaultValues localDefaultValues = FRContext.getDefaultValues();
      localFRFont = localDefaultValues.getFRFont();
    }
    else
    {
      localFRFont = localFRFont.applyShadow(paramBoolean);
    }
    return paramStyle.deriveFRFont(localFRFont);
  }

  public static Style setReportSuperscript(Style paramStyle, boolean paramBoolean)
  {
    FRFont localFRFont = paramStyle.getFRFont();
    if (localFRFont == null)
    {
      DefaultValues localDefaultValues = FRContext.getDefaultValues();
      localFRFont = localDefaultValues.getFRFont();
    }
    else
    {
      localFRFont = localFRFont.applySuperscript(paramBoolean);
    }
    return paramStyle.deriveFRFont(localFRFont);
  }

  public static Style setReportSubscript(Style paramStyle, boolean paramBoolean)
  {
    FRFont localFRFont = paramStyle.getFRFont();
    if (localFRFont == null)
    {
      DefaultValues localDefaultValues = FRContext.getDefaultValues();
      localFRFont = localDefaultValues.getFRFont();
    }
    else
    {
      localFRFont = localFRFont.applySubscript(paramBoolean);
    }
    return paramStyle.deriveFRFont(localFRFont);
  }

  public static Style setReportFontUnderline(Style paramStyle, boolean paramBoolean)
  {
    FRFont localFRFont = paramStyle.getFRFont();
    if (localFRFont == null)
    {
      DefaultValues localDefaultValues = FRContext.getDefaultValues();
      localFRFont = localDefaultValues.getFRFont();
    }
    else if (paramBoolean)
    {
      localFRFont = localFRFont.applyUnderline(1);
    }
    else
    {
      localFRFont = localFRFont.applyUnderline(0);
    }
    return paramStyle.deriveFRFont(localFRFont);
  }

  public static Style setReportFontUnderline2(Style paramStyle, int paramInt)
  {
    FRFont localFRFont = paramStyle.getFRFont();
    if (localFRFont == null)
    {
      DefaultValues localDefaultValues = FRContext.getDefaultValues();
      localFRFont = localDefaultValues.getFRFont();
    }
    else
    {
      localFRFont = localFRFont.applyUnderline(paramInt);
    }
    return paramStyle.deriveFRFont(localFRFont);
  }

  public static Style setReportFontSize(Style paramStyle, int paramInt)
  {
    FRFont localFRFont = paramStyle.getFRFont();
    if (localFRFont == null)
    {
      localObject = FRContext.getDefaultValues();
      localFRFont = ((DefaultValues)localObject).getFRFont();
    }
    Object localObject = localFRFont.applySize(paramInt);
    return ((Style)paramStyle.deriveFRFont((FRFont)localObject));
  }

  public static Style setReportFontForeground(Style paramStyle, Color paramColor)
  {
    FRFont localFRFont = paramStyle.getFRFont();
    if (localFRFont == null)
    {
      DefaultValues localDefaultValues = FRContext.getDefaultValues();
      localFRFont = localDefaultValues.getFRFont();
    }
    else
    {
      localFRFont = localFRFont.applyForeground(paramColor);
    }
    return paramStyle.deriveFRFont(localFRFont);
  }

  public static String formatToPattern(Format paramFormat)
  {
    if (paramFormat == null)
      return "";
    if (paramFormat instanceof SimpleDateFormat)
      return ((SimpleDateFormat)paramFormat).toPattern();
    if (paramFormat instanceof DecimalFormat)
      return ((DecimalFormat)paramFormat).toPattern();
    return "";
  }

  public static String frFontToString(FRFont paramFRFont)
  {
    if (paramFRFont == null)
      return "";
    return "[" + paramFRFont.getFamily() + "," + paramFRFont.getStyleName() + "," + paramFRFont.getSize() + "]";
  }
}